<template>
  <div class="product-detail">
    <div class="card" @click="$router.replace(`/shop/${product.id}`)">
      <el-image :src="product.images[0]" alt="Product Image" class="product-image" />
      <div class="product-info" v-if="product">
        <h4 style="font-size: 16px">{{ product.name }}</h4>
        <div class="attribute">
          <span>店铺名称：</span>
          {{ product.shopName }}
        </div>
        <div class="attribute">
          <span>价格：</span>
          ¥{{ decimalPointSave(product.price) }}
        </div>
        <div class="attribute">
          <span>积分：</span>
          ∫{{ decimalPointSave(product.integral) }}
        </div>
        <div class="attribute">
          <span>数量：</span>
          {{ product.number }}
        </div>
      </div>
      <div class="total">
        <span style="color: gray">¥{{ decimalPointSave(product.number * product.price) }}</span>
        <span style="display: inline-block; width: 10px"></span>
        <span style="color: gray">∫{{ decimalPointSave(product.number * product.integral) }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { decimalPointSave } from '@/utils/strutils'
import { onMounted } from 'vue'
import { getFile } from '@/utils/fileutils.js'

const props = defineProps({
  obj: Object,
})

const product = props.obj

const changeImageFormat = async () => {
  product.images = await Promise.all(product.images.map(async (image) => await getFile(image)))
}

// 转化图片格式
onMounted(() => {
  changeImageFormat()
})
</script>

<style scoped less="scss">
.product-detail {
  width: 100%;
  height: 120px;
  padding: 2px;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.5s;

  .card {
    display: flex;
    gap: 20px;
    align-items: center;

    position: relative;

    .product-image {
      height: 116px;
      border-radius: 8px;
    }

    .product-info {
      .attribute {
        font-size: 14px;
        color: grey;
      }
    }

    .total {
      position: absolute;
      top: 80%;
      right: 5%;
    }
  }
}

.product-detail:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
</style>
